package com.tsingeye.viid.controller;

import cn.hutool.core.collection.CollUtil;
import com.tsingeye.common.config.MinioConfig;
import com.tsingeye.common.core.controller.BaseController;
import com.tsingeye.common.core.page.TableDataInfo;
import com.tsingeye.common.utils.StringUtils;
import com.tsingeye.viid.domain.ViidMotorVehicleImage;
import com.tsingeye.viid.service.ViidMotorVehicleImageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 机动车照片Controller
 *
 * @author 姜风
 * @date 2022-04-21
 */
@Api(tags = "机动车照片")
@RestController
@RequestMapping("/viid/motorvehicleimage")
public class ViidMotorVehicleImageController extends BaseController {

    @Autowired
    private MinioConfig minioConfig;

    @Autowired
    private ViidMotorVehicleImageService viidMotorVehicleImageService;

    /**
     * 查询机动车照片列表
     */
    @ApiOperation(value = "分页查询机动车图片" , notes = "分页查询接口")
    @PreAuthorize("@ss.hasPermi('viid:motorvehicleimage:list')")
    @GetMapping("/list")
    public TableDataInfo list(ViidMotorVehicleImage viidMotorVehicleImage) {
        startPage();
        List<ViidMotorVehicleImage> list = viidMotorVehicleImageService.selectViidMotorVehicleImageList(viidMotorVehicleImage);
        // 遍历list
        if (CollUtil.isNotEmpty(list)) {
            for (ViidMotorVehicleImage motorVehicleImage : list) {
                if (StringUtils.isNotEmpty(motorVehicleImage.getImageUrl())) {
                    motorVehicleImage.setImageUrl(minioConfig.getUrl() + motorVehicleImage.getImageUrl());
                }
            }
        }
        return getDataTable(list);
    }
}
